﻿using Newtonsoft.Json;
using Prism.Mvvm;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Windows;

namespace PLCSharp.Views.Robots
{
    public class Robot : BindableBase
    {
        [Key]
        public Guid ID { get; set; } = Guid.NewGuid();
        private string _Name;
        /// <summary>
        /// Comment
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set
            {
                if (_Name != value)
                {
                    Prompt = "已修改，请保存";
                }
                SetProperty(ref _Name, value);
            }
        }
        private RobotType _Type;
        /// <summary>
        /// 
        /// </summary>
        public RobotType Type
        {
            get { return _Type; }
            set
            {
                if (_Type == RobotType.Undefined)
                {
                    SetProperty(ref _Type, value);
                }
                else
                {

                    MessageBox.Show("选定型号后不可改变！");
                }
            }
        }

        private string _Connect;
        /// <summary>
        /// 
        /// </summary>
        public string Connect
        {
            get { return _Connect; }
            set { SetProperty(ref _Connect, value); }
        }
        private string _Comment;
        /// <summary>
        /// 注释
        /// </summary>
        public string Comment

        {
            get { return _Comment; }
            set
            {
                if (_Comment != value)
                {
                    Prompt = "已修改，请保存";
                }
                SetProperty(ref _Comment, value);
            }
        }
        [Column("Params")]
        public string SerializedParams
        {
            get => JsonConvert.SerializeObject(Params); // 自动序列化
            set => Params = JsonConvert.DeserializeObject<RobotParams>(value); // 自动反序列化

        }

        private string _Prompt;
        [NotMapped]
        /// <summary>
        /// 提示
        /// </summary>
        public string Prompt
        {
            get { return _Prompt; }
            set { SetProperty(ref _Prompt, value); }
        }
        private bool _Online;

        [NotMapped]
        /// <summary>
        /// 在线
        /// </summary>
        public bool Online
        {
            get { return _Online; }
            set { SetProperty(ref _Online, value); }
        }
        private void ParamsChanged()
        {


        }
        private RobotParams _Params;
        [NotMapped]
        /// <summary>
        /// Comment
        /// </summary>
        public RobotParams Params
        {
            get
            {
                _Params ??= new RobotParams();
                return _Params;
            }
            set
            {
                SetProperty(ref _Params, value);
            }
        }
        public class RobotParams : BindableBase
        {


        }

    }
}
